/**
 * File:   Identifier.java
 * Author: Gvennet
 */
package dht.async;

import java.util.Random;

/** Provides a 160-bit node identifier. */
public abstract class Identifier implements Comparable<Identifier>
{

    /**
     * Creates a new random identifier.
     *
     * @param length the identifier length in bytes
     *
     * @return a new random identifier.
     */
    public static Identifier randomIdentifier(int length)
    {
        //return IntegerIdentifier.randomIdentifier(length);
        return ByteArrayIdentifier.randomIdentifier(length);
    }

    /**
     * Creates a new random identifier.
     *
     * @param length the identifier length in bytes
     * @param random the random generator
     *
     * @return a new random identifier.
     */
    public static Identifier randomIdentifier(int length, Random random)
    {
        //return IntegerIdentifier.randomIdentifier(length, random);
        return ByteArrayIdentifier.randomIdentifier(length,random);
    }


    /** Creates a new <code>Identifier</code> object. */
    protected Identifier()
    {
    }


    /**
     * Returns the identifier length in bytes.
     *
     * @return the identifier length
     */
    public abstract int getLength();

    /**
     * Evaluates a distance to the identifier
     *
     * @param identifier the identifier to evaluate distance to
     *
     * @return a distance to the identifier
     *
     * @throws NullPointerException if <code>identifier</code> is <code>null</code>
     * @throws IllegalArgumentException if <code>identifier</code> has different length
     */
    public abstract Identifier getDistance(Identifier identifier);

    public abstract int getHighestOneBitPosition(); //todo

}

